package com.studentManagement.serviceImpl;

import com.studentManagement.dao.DormitoryDao;
import com.studentManagement.dao.StudentDao;
import com.studentManagement.daoImpl.ClassDaoImpl;
import com.studentManagement.daoImpl.DormitoryDaoImpl;
import com.studentManagement.daoImpl.StudentDaoImpl;
import com.studentManagement.po.Student;
import com.studentManagement.po.Student_Leader;
import com.studentManagement.po.Student_simple;
import com.studentManagement.service.ClassService;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by Administrator on 2017/5/1 0001.
 */
public class ClassServiceImpl implements ClassService {
    @Override // (查询begin-end]之前学生表信息（class_id)老师
    public List<Student_simple> forRightClassServlet_getStudentList(String class_id, int begin, int end) {
        List<Student_simple> list = new StudentDaoImpl().queryStudentByClass_id(class_id, begin, end);
        return list;
    }
    @Override //得到分页页数（class_id，每页个数）
    public int getPagingNum_class_id(String class_id, int num) {
        int sum = 0;
        try {
            sum = new StudentDaoImpl().queryStudentSumByClass_id(class_id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (sum % num == 0) {
            return sum / num;
        } else {
            return sum / num + 1;
        }
    }

    @Override   //得到分页页数（关键字,每页个数）
    public int getPagingNum_keywords(String keywords,int num) {
        int sum = 0;
        try {
            sum = new StudentDaoImpl().queryStudentSumByKeywords(keywords);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (sum % num == 0) {
            return sum / num;
        } else {
            return sum / num + 1;
        }
    }

    @Override//添加学生（Student）
    public void addStudent(Student student) throws SQLException {
        new StudentDaoImpl().addStudent(student);
    }
    @Override//得到宿舍列表(class_id)
    public List<String> getDormitory_id(String class_id) {
        DormitoryDao dormitory = new DormitoryDaoImpl();
        return dormitory.queryDormitory_idByClass_id(class_id);
    }
    @Override//判断学号能否使用
    public boolean student_idCanUsed(String student_id) {
        StudentDao student = new StudentDaoImpl();
        return student.Student_idCanUsed(student_id);
    }
    @Override//通过班级获取班委列表
    public List<Student_Leader> getStudent_leader(String class_id) {
        StudentDao student = new StudentDaoImpl();
        return student.queryStudentLeader(class_id);
    }
    @Override//删除学生（student_id)
    public boolean delStudent(String student_id)  {
        StudentDao student =new StudentDaoImpl();
        return student.deleteStudent(student_id);
    }
    @Override//得到学生的详细信息（student_id)
    public Student getStudentDeTail(String student_id) {
        Student student=new StudentDaoImpl().queryStudentDetail(student_id);
        return student;
    }
    @Override//更新学生信息（student_id)
    public void updateStudentDetail(Student student) {
        new StudentDaoImpl().updateStudentDetail(student);
    }
    @Override//得到学生头像路径（student_id)
    public String getStudentImg(String student_id) {
        return new StudentDaoImpl().queryStudentImg(student_id);
    }
    @Override//得到所有班级列表
    public List<String> getClassList() {
        return new ClassDaoImpl().queryAllClass_id();
    }
}
